<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateUsersTable extends Migration
{
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {

        	$table->id();

            $table->unsignedBigInteger('parent_id')->default(0)->index();
	        $table->boolean('is_parent')->default(false);
	        $table->string('grade')->default('vip')->index();
	        $table->string('invite_code', 10)->unique();
	        $table->decimal('balance', 10, 2)->default(0);
	        $table->decimal('freeze', 10, 2)->default(0);
	        $table->decimal('quote', 10, 2)->default(1000);
	        $table->decimal('spend', 10, 2)->default(0)->comment('money from balance only for spending');
	        $table->decimal('dividend_brokerage', 10, 2)->default(0)->index()->comment('accumulated product brokerage');
	        $table->dateTime('vip_expired_at')->nullable();


	        $table->unsignedInteger('notifications_count')->default(0);

	        $table->string('name', 30)->nullable()->index();
	        $table->string('nickname', 30)->nullable();
	        $table->string('phone', 15)->nullable()->unique();
	        $table->string('signature')->nullable();
	        $table->string('password')->nullable();
	        $table->string('pay_code')->nullable();
            $table->timestamp('password_reset_sms_at')->nullable();

	        $table->string('avatar')->nullable();
	        $table->string('gender')->default('female');
	        $table->date('birthday')->nullable();

	        $table->decimal('dividend_all', 10, 2)->default(0)->index()->comment('accumulated total dividend sum');
	        $table->decimal('dividend_day', 10, 2)->default(0)->index()->comment('accumulated today dividend sum');

	        $table->string('wm_openid', 32)->unique()->nullable();
	        $table->string('wm_session_key', 32)->nullable();
	        $table->string('wx_unionid', 32)->unique()->nullable();
	        $table->string('wx_openid', 32)->unique()->nullable();
	        $table->string('wx_nickname', 32)->nullable();
	        $table->string('wx_sex')->nullable();
	        $table->string('wx_headimgurl')->nullable();
	        $table->string('wx_country')->nullable();
	        $table->string('wx_province')->nullable();
	        $table->string('wx_city')->nullable();
	        $table->string('wx_qrcode')->nullable();
	        $table->string('alipay_user_id', 32)->unique()->nullable();
	        $table->string('alipay_nickname')->nullable();
	        $table->string('alipay_avatar')->nullable();
	        $table->string('alipay_province')->nullable();
	        $table->string('alipay_city')->nullable();

	        $table->string('address')->nullable();
	        $table->text('last_token')->nullable();

	        $table->unsignedInteger('attentions')->default(0);
	        $table->unsignedInteger('fans')->default(0);
	        $table->boolean('is_locked')->default(false);

	        $table->string('register_unique_code')->nullable();
	        $table->boolean('is_new')->default(false);

            $table->timestamps();
        });
    }

    public function down()
    {
        Schema::dropIfExists('users');
    }
}
